<template>
<!-- ref一般绑定子组件 -->
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'


export default {
  name: "Scroll",
  props: {
    probeType: {
      type: Number,
      default: 0
    },
    pullUpLoad: {
      type: Boolean,
      default: true
    }
  },
  data(){
    return {
      bscroll: null,
    }
  },
  mounted() {
    this.bscroll = new BScroll(this.$refs.wrapper, {
      click: true,
      probeType: this.probeType,
      pullUpLoad: this.pullUpLoad
    })

    //监听滚动的位置
    this.bscroll.on('scroll', (position) => {
      // console.log(position);
      this.$emit("scroll", position)
    })
    //监听上拉事件
    this.bscroll.on('pullingUp', ()=> {
      this.$emit("pullingUp")
    })

    console.log(this.bscroll);
  },
  methods: {
    getRefresh(){
      console.log("----------");
      this.bscroll && this.bscroll.refresh()
    },
    getSaveY(){
      return this.bscroll ? this.bscroll.y : 0
    }
  }
}
</script>

<style>

</style>